#ifndef __DirectShowMovieTexture_H__
#define __DirectShowMovieTexture_H__
 
#include <Ogre.h>
#include <OgreVector2.h>
 
#include <dshow.h>
#include <Qedit.h>// for sample grabber
#include <windows.h>

namespace OgreUtils
{
    struct DirectShowData
    {
        /// Graph object
        IGraphBuilder *pGraph;
        /// Media control object
        IMediaControl *pControl;
        /// Media event object
        IMediaEvent *pEvent;
        /// Grabber filter
        IBaseFilter *pGrabberF;
        /// Grabber object
        ISampleGrabber *pGrabber;
        /// Interface for seeking object
        IMediaSeeking *pSeeking;
        /// Window interface
        /** Useful for some configuration
        */
        IVideoWindow *pWindow;
 
        /// Video output width
        int videoWidth;
        /// Video output height
        int videoHeight;
    };
 
    /// Util function for converting C strings to wide strings
    /** (as needed for path in directshow). */
    WCHAR* util_convertCStringToWString(const char* string);
 
    /// A class for playing movies in an ogre texture
    class DirectShowMovieTexture
    {
    public:
        // cons / decons
        /// Initializes the dshow object, and creates a texture with the given dimensions.
        /**
        If dontModifyDimensions is false, the system might modify the texture dimensions
        by setting them to the nearest power of two (useful for old computers).
        (Ie, 1024x512 if the original dimensions were 640x480).
        */
        DirectShowMovieTexture(int width, int height, bool dontModifyDimensions=true);
        /// Destroys the dshow object
        virtual ~DirectShowMovieTexture();
 
        // basic movie methods
        /// Loads a given movie
        /**
        /param moviePath A string telling the full path of the file to be loaded.
        /param horizontalMirroring A bool telling whether the video should be rendered
        as if seen through a mirror, or not.
        */
        void loadMovie(const Ogre::String& moviePath, bool horizontalMirroring=false);
        /// Obtains the dimensions of the current movie
        Ogre::Vector2 getMovieDimensions();
        /// Unloads the current movie
        void unloadMovie();
 
        // methods for movie control
        /// Pauses the current movie
        void pauseMovie();
        /// Starts playing the current movie
        void playMovie();
        /// Makes the current movie rewind
        void rewindMovie();
        /// Stops the current movie
        void stopMovie();
        /// Is the latest video put to play, now playing?
        /** (This is an old implementation of mine; I guess I should re-check this) */
        bool isPlayingMovie();
 
        // methods on movie texture
        /// Obtain the ogre texture where the movie is rendered
        Ogre::TexturePtr getMovieTexture();
        /// Render a movie frame in the ogre texture
        void updateMovieTexture();
    protected:
        /// Texture where to render the movie
        Ogre::TexturePtr mTexture;
        /// Real texture width
        Ogre::Real mTexWidth;
        /// Real texture height
        Ogre::Real mTexHeight;
        /// Direct Show specific data
        DirectShowData* dsdata;
        /// Do we do horizontal mirroring by software?
        bool mHorizontalMirroring;
 
        /// Clean the full texture (paint it all black)
        void cleanTextureContents();
    };
}
 
#endif // __FILE_UTILSOGREDSHOW_INCLUDED
